﻿using System;
using System.IO;

namespace MoBaoPay.Model.Request
{
    /// <summary>
    /// 摩宝支付，通知回调参数
    /// </summary>
    public class MoBaoNotifyInput
    {
        /// <summary>
        /// 商户号
        /// </summary>
        public string CustNo { get; set; }

        /// <summary>
        /// 支付时上送的商户参数
        /// </summary>
        public string MerchParam { get; set; }

        /// <summary>
        /// 商户订单号
        /// </summary>
        public string MerchTradeNo { get; set; }

        /// <summary>
        /// 商户通知地址
        /// </summary>
        public string MerchUrl { get; set; }

        /// <summary>
        /// 通知时间
        /// </summary>
        public string NotifyTime { get; set; }

        /// <summary>
        /// 摩宝系统订单号
        /// </summary>
        public string OrderNo { get; set; }

        /// <summary>
        /// 订单结果
        /// </summary>
        public string OrderStatus { get; set; }
        
        /// <summary>
        /// 实际交易金额
        /// </summary>
        public decimal TradeAmt { get; set; }
            
        /// <summary>
        /// 商户交易日期
        /// </summary>
        public string TradeTime { get; set; }
        
        /// <summary>
        /// 签名
        /// </summary>
        public string SignMsg { get; set; }

        /// <summary>
        /// 验证签名是否正确
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool Verify(string fileName)
        {
            var strData =
                $"custNo={CustNo}" +
                (string.IsNullOrWhiteSpace(MerchParam) ? string.Empty : $"&merchParam={MerchParam}") +
                $"&merchTradeNo={MerchTradeNo}&merchUrl={MerchUrl}&notifyTime={NotifyTime}&orderNo={OrderNo}&orderStatus={OrderStatus}&tradeAmt={TradeAmt}&tradeTime={TradeTime}";

            return MD5WithRSA.Verify(fileName, strData, this.SignMsg);
        }
    }
}